Шаблон:Graph:Population history

Материал из Википедии — свободной энциклопедии
Перейти к навигации Перейти к поиску
Документация

This graph's main version resides at mediawiki Template:Graph:Population_history. Please make all the changes there and copy it everywhere else (until the copying is automated)

{{Graph:Population history|Q84}}
Show London's population history from Wikidata
Графики недоступны из-за технических проблем. См. информацию на Фабрикаторе и на mediawiki.org.
{{Graph:Population history

| table=Wikidata/St.Petersburg.tab
| atable=Original/St.Petersburg population annotations.tab}}
Show population of St.Petersburg from the table on Commons, with annotations

Графики недоступны из-за технических проблем. См. информацию на Фабрикаторе и на mediawiki.org.

Inserts a graph with the population history for the given city.

Параметры шаблона[Править данные шаблона]

Шаблон использует блочное форматирование параметров.

ПараметрОписаниеТипСтатус
City Wikidata ID1

Wikidata ID of the city or region

По умолчанию
Q84
Строковый (без форматирования)необязательный
Title of the data page on Commonstable

Data page name on Commons, without the Data: prefix. The table must contain "year" and "population" columns.

Строковый (без форматирования)необязательный
Raw values for this graphvalues

Supply all values as a list of JSON objects: {"year":1980, "population":1000}, {"year":1984, "population":1045}, ...

Неизвестнонеобязательный
Title of the annotations data page on Commonsatable

Data page name on Commons, without the Data: prefix. The table must contain "year" column, and optional "text" and "color" columns.

Строковый (без форматирования)необязательный
Raw annotation valuesavalues

Supply all annotation values as a list of JSON objects: {"year":1980, "text":"Big event"}, ...

Неизвестнонеобязательный
Graph colorcolor

Shade with which to highlight the data in the chart

По умолчанию
#00f
Пример
#f00
Строковый (без форматирования)необязательный
Graph scalescale

Scaling could be one of these: linear, log, pow, sqrt, quantile, quantize, and threshold

По умолчанию
linear
Пример
log
Строковый (без форматирования)необязательный
Maximum Y value axismax

This optional value might be useful to align multiple graphs side-by-side

По умолчанию
Automatically scaled to the data.
Пример
10000
Числонеобязательный
Widthwidth

Width for the chart in pixels, if different from the default.

По умолчанию
400
Числонеобязательный
Heightheight

Height for the chart in pixels, if different from the default.

По умолчанию
200
Числонеобязательный

См. также[править код]

  • {{Wikidata/Population}}
  • {{Население.wd}}
<graph>
{
  //
  // ATTENTION: This code is maintained at https://www.mediawiki.org/wiki/Template:Graph:Population_history
  //            Please do not modify it anywhere else, as it may get copied and override your changes.
  //            Suggestions can be made at https://www.mediawiki.org/wiki/Template_talk:Graph:Population_history
  //

  "version": 2,
  "width": 400,
  "height": 200,

  // The population data could be from Commons dataset, Wikidata, or hardcoded values
  "data": [
    {
      "name": "table",
"url": "wikidatasparql:///?query=SELECT%20%28MAX%28%3Fpopulation_entry%29%20as%20%3Fpopulation%29%20%3Fyear%20WHERE%20%7B%0A%20%20%20%20%23%20set%20the%20item%20here%20-%20e.g.%20city%2C%20country%0A%09BIND%28wd%3AQ84%20as%20%3Fitem%29%0A%20%20%20%20%3Fitem%20p%3AP1082%20%3Fpopstatement%20.%0A%20%20%20%20%3Fpopstatement%20ps%3AP1082%20%3Fpopulation_entry%20.%0A%20%20%20%20OPTIONAL%20%7B%0A%20%20%20%20%20%20%3Fpopstatement%20pq%3AP585%20%3Fdate%20.%0A%20%20%20%20%20%20BIND%28year%28%3Fdate%29%20as%20%3Fyear%29%0A%20%20%20%20%7D%0A%7D%20GROUP%20BY%20%3Fyear%20ORDER%20BY%20ASC%28%3Fyear%29",
      "format": { "type": "json" },
      // Convert year integer (2016) into a date object (2016-01-01)
      "transform": [
      	// Optionally filter data with an template expression parameter
      	// e.g.  filter = datum.year > 1900 && datum.year < 2000

      	{ "type": "formula", "field": "date", "expr": "utc(datum.year,0,1)" }
      ]
    },

    // Each annotation is expected to be an integer year, string text,
    // and optional string color (e.g. "#4d2800")
    {
      "name": "annotations",
"values": [],
      "transform": [
        { "type": "formula", "field": "date", "expr": "utc(datum.year,0,1)" },
        { "type": "formula", "field": "color", "expr": "datum.color||'#000'" }
      ]
    }
  ],

  "scales": [
    // The dates are scaled to the "x" axis - the width of the graph
    {
      "name": "x",
      "type": "utc",
      "range": "width",
      "domain": {"data": "table","field": "date"}
    },
    // The population are scaled to the "y" axis - the height of the graph
    // Optional scale parameter can change "linear" to other scales like log
    // Optional max parameter can fix the upper bound of the graph
    {
      "name": "y",
      "type": "linear",
      "range": "height",
      "domain": {"data": "table","field": "population"},
      "clamp": true,

      "nice": true
    }
  ],

  // Simple axis with horizontal grid lines
  "axes": [
    {"type": "x", "scale": "x", "ticks": 5},
    {"type": "y", "scale": "y", "ticks": 5, "grid": true, "orient":"right"}
  ],

  // The graph is drawn with two elements a thick line at the top,
  // and a semi-transparent area below
  "marks": [
    {
      "type": "area",
      "from": {"data": "table"},
      "properties": {
        "enter": {
          "x": {"scale": "x", "field": "date"},
          "y": {"scale": "y", "value": 0},
          "y2": {"scale": "y", "field": "population"},
          "fill": {"value": "#99B2CC"},
          "fillOpacity": {"value": 0.35},
          "interpolate": {"value": "monotone"}
        }
      }
    },
    // If annotations are given, draw dashed line with associated text
    {
      "type": "rule",
      "from": {"data": "annotations"},
      "properties": {
        "enter": {
          "x": {"scale": "x", "field":"date"},
          "y": {"value": 0},
          "y2": {"signal": "height"},
          "stroke": {"field": "color"},
          "strokeWidth": {"value": 2},
          "opacity": {"value": 0.6},
          "strokeDash": {"value": [8,3]}
        }
      }
    },
    {
      "type": "line",
      "from": {"data": "table"},
      "properties": {
        "enter": {
          "x": {"scale": "x","field": "date"},
          "y": {"scale": "y","field": "population"},
          "stroke": {"value": "#99B2CC"},
          "strokeWidth": {"value": 3},
          "interpolate": {"value": "monotone"}
        }
      }
    },
    // The small white circles should be drawn after annotations but before text
    {
      "type": "symbol",
      "from": {"data": "table"},
      "properties": {
        "enter": {
          "x": {"scale": "x","field": "date"},
          "y": {"scale": "y","field": "population"},
          "stroke": {"value": "#99B2CC"},
          "fill": {"value": "#fff"},
          "size": {"value": 30}
        }
      }
    },
    // Annotation text
    {
      "type": "text",
      "from": {"data": "annotations"},
      "properties": {
        "enter": {
          "x": {"scale": "x", "field":"date"},
          "y": {"value": 0},
          "align": {"value": "right"},
          "baseline": {"value": "bottom"},
          "angle": {"value": 270},
          "dx": {"value": -4},
          "dy": {"value": -2},
          "text": {"field": "text"},
          "stroke": {"field": "color"}
        }
      }
    }

  ]
}
</graph>